﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BCL.Repository;
using Azad;
using BCL.Entity;
using NazSoft.Framework.Extensions;
using System.Web.UI.HtmlControls;
public class CustomGroup<TKey, TValue>
{
    public TKey Key { get; set; }
    public IEnumerable<TValue> Values { get; set; }
}
public partial class Archive : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindDropDown();
    }

    void BindDropDown()
    {
        //NewsThumbnails.ItemDataBound += new RepeaterItemEventHandler(NewsThumbnails_ItemDataBound);
        SilverlightService silverlightService = new SilverlightService();


        var archives = silverlightService.ArchiveDate(null);

        archives = archives.OrderByDescending(x => x.CurrentDate).ToList();
        var g = archives.GroupBy(x => x.CurrentDate.ToString("MMMM yyyy"));

        IEnumerable<CustomGroup<String, LogoInformation>> result = g.Select(x => new CustomGroup<String, LogoInformation>() { Key = x.Key, Values = x });

        NewsThumbnails.DataSource = result;
        NewsThumbnails.DataBind();

    }

    protected void NewsThumbnails_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LogoInformation log = e.Item.DataItem as LogoInformation;
        if (log != null)
        {
            HtmlAnchor html = e.Item.FindControl("news_image") as HtmlAnchor;
            HtmlAnchor A1 = e.Item.FindControl("A1") as HtmlAnchor;

            DateTime today = log.CurrentDate;
            html.HRef = string.Format("/{0}/{1}/{2}", today.Year, today.Month.ZeroPad(), today.Day.ZeroPad());
            A1.HRef = string.Format("/{0}/{1}/{2}", today.Year, today.Month.ZeroPad(), today.Day.ZeroPad());
        }
    }
}